<template>
  <van-row>
    <van-col span="24">
      <!-- 列表项 -->
        <van-row style="margin-top: 5px;cursor: pointer;" v-for="order in orderList" :key="order.orderId">
            <van-col :span="24">
                <van-row>
                    <van-col :span="22" :offset="2">订单编号:{{order.orderNumber}}</van-col>
                </van-row>
                <van-row>
                    <van-col :span="22" :offset="2">下单时间:{{order.orderDate}}</van-col>
                </van-row>
                <van-row>
                    <van-col :span="22" :offset="2">总金额:{{order.orderTotal}}</van-col>
                </van-row>
                <van-row>
                    <van-col :span="22" :offset="2">下单用户:{{order.user.username}}</van-col>
                </van-row>
            </van-col>
        </van-row>
    </van-col>
  </van-row>
</template>

<script setup>
import { ref,getCurrentInstance, onMounted } from 'vue';
import { showNotify } from 'vant';
import '@vant/touch-emulator';

const {proxy} = getCurrentInstance();

const orderList = ref([]);

const getOrderByUserId = ()=>{
    proxy.$axios({
        method: 'get',
        url: '/order/user/'+userId.value
    }).then(res=>{
        let resultBean = res.data;
        if(resultBean.code == 200){
           orderList.value = resultBean.data;
        }else{
            showNotify({message: resultBean.msg});
        }
    }).catch(error=>{
        showNotify({message: error.message});
    })
}

const userId = ref(null);

onMounted(()=>{
    userId.value = 1;
    getOrderByUserId();
})

</script>

<style>
</style>
